import type { MenuItem } from 'electron';

const { Menu, app } = require('electron');
const isMac = process.platform === 'darwin';
const template = [
  ...(isMac
    ? [
        {
          label: app.name,
          submenu: [
            { role: 'about', label: '关于HRecorder' },
            { type: 'separator' },
            { role: 'services', label: '服务' },
            { type: 'separator' },
            { type: 'separator' },
            { role: 'quit', label: '退出HRecorder' }
          ]
        }
      ]
    : []),
  {
    label: '编辑',
    submenu: [
      { role: 'undo', label: '撤销' },
      { role: 'redo', label: '重做' },
      { type: 'separator' },
      { role: 'cut', label: '剪切' },
      { role: 'copy', label: '拷贝' },
      { role: 'paste', label: '粘贴' },
      isMac && { role: 'pasteAndMatchStyle', label: '粘贴并匹配样式' },
      { role: 'delete', label: '删除' },
      { role: 'selectAll', label: '全选' },
      { type: 'separator' }
    ].filter(Boolean)
  },
  {
    label: '显示',
    submenu: [
      { role: 'reload', label: '刷新' },
      { role: 'forceReload', label: '强制刷新' },
      {
        label: '重启',
        click: () => {
          console.log('点击重启');
          app.relaunch();
          app.exit();
        }
      },
      { type: 'separator' },
      { role: 'resetZoom', label: '默认大小' },
      { type: 'separator' },
      { role: 'togglefullscreen', label: '进入全屏幕' }
    ].filter(Boolean)
  },
  {
    label: '窗口',
    submenu: [
      { role: 'minimize', label: '最小化' },
      { role: 'zoom', label: '缩放' },
      ...(isMac
        ? [{ type: 'separator' }, { role: 'front', label: '前置全部窗口' }]
        : [{ role: 'close' }])
    ]
  }
];

const menu = Menu.buildFromTemplate(template as unknown as MenuItem[]);
Menu.setApplicationMenu(menu);

export {};
